package com.liu.controller;

import com.liu.domain.room;
import com.liu.repository.RoomRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by liu on 17-9-21.
 */

@RestController
public class RoomController {
    private final static Logger logger = LoggerFactory.getLogger(RoomController.class);

    @Autowired
    private RoomRepository roomRepository;

    /*
    查询所有寝室列表
     */
    @GetMapping(value = "/room")
    public List<room> roomList(){
//        System.out.println("roomList");
//        logger.info("roomList");
        return roomRepository.findAll();
    }
    @RequestMapping("/rooms/{build}")
    public List<room> roomListByBuild(@PathVariable("build") int build){
        return roomRepository.findAllByBuild_id(build);
    }
    /*
    添加一个寝室
     */
    @PostMapping(value = "/room")
    public room studentAdd(room ro) {


        return roomRepository.save(ro);
    }

    /*
    更新一个寝室的信息
     */
    @PutMapping(value = "/room/{id}")
    public room studentUpdate(@PathVariable("id") int id, room ro) {

        return roomRepository.save(ro);
    }
    /*
    删除一个寝室
     */

    @DeleteMapping(value = "/room/{id}")
    public void studentDelete(@PathVariable("id") int id){
        roomRepository.delete(id);
    }
}
